package com.lzh.socket;

import java.io.*;
import java.net.Socket;

/**
 * @author liuzhihao
 * @create 2022-07-02 21:15
 *
 * 客户端
 */
public class ClientSocket {

    public static void main(String[] args) {
        try {
            // 初始化一个socket
            Socket socket = new Socket("127.0.0.1", 9999);
            // 通过socket获取字符流
            BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            // 通过标准输入流获取字符流
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
            // 一直等待输入
            while (true) {
                String str = bufferedReader.readLine(); // 获取输入的内容
                bufferedWriter.write(str);
                bufferedWriter.write("\n");
                bufferedWriter.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
